package com.android.dialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.android.library.R;
import com.android.library.utils.ToastUtils;


/**
 * Created by aaronhu on 2018/4/4.
 */

public class InitDialogFragment extends DialogFragment {
    private EditText mEtMemberShip;
    private TextView mBtnConfirm;
    private OnConfirmClickListener onConfirmClickListener;
    private String number = "fc754077-7041-4422-aa5a-223511b43b23";

    public InitDialogFragment() {
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_MinWidth);
        setCancelable(false);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_init, null);
        mEtMemberShip = (EditText) view.findViewById(R.id.et_member_ship);
        mBtnConfirm = (TextView) view.findViewById(R.id.tv_confirm);
        mBtnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEtMemberShip.getText())) {
                    ToastUtils.showToast("请输入认证序列号");
                } else {
                    if (onConfirmClickListener != null) {
                        onConfirmClickListener.onClick(number);
                        dismiss();
                    }
                }
            }
        });
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        return super.onCreateDialog(savedInstanceState);
    }

    public interface OnConfirmClickListener {
        void onClick(String memberShip);
    }

    public void setOnConfirmClickListener(OnConfirmClickListener onConfirmClickListener) {
        this.onConfirmClickListener = onConfirmClickListener;
    }

}
